package com.xxzb.pack0820;

import java.io.*;

//数据流 了解内容
//数据流：DataInputStream、DataOutputStream等提供将基础数据写入到文件中，或者读取出来
public class DemoG {
    //读取
    public static void a() throws Exception{
File file =new File("F:\\yongpangaofeng\\a.txt");
InputStream in=new FileInputStream(file);
//专门用于基本数据类型和String操作
        DataInputStream dis =new DataInputStream(in);
        boolean b = dis.readBoolean();
        byte by = dis.readByte();
        int i = dis.readInt();
        String s = dis.readUTF();
        System.out.println(b);
        System.out.println(by);
        System.out.println(i);
        System.out.println(s);
        dis.close();
        in.close();
    }
    //写入
    public static void b() throws Exception{
        File file=new File("F:\\yongpangaofeng\\a.txt");
        OutputStream out=new FileOutputStream(file);
        //专门用于基本数据类型和String的操作
        DataOutputStream dos=new DataOutputStream(out);
        dos.writeBoolean(true);
        dos.writeByte(4);
        dos.writeInt(1988);
        dos.writeUTF("Hello,World!");
        dos.close();
        out.close();
    }


    public static void main(String[] args) throws Exception{
        //先写进去，在读出来
        b();
        a();
    }
}
